package TUILayer;
import java.util.Scanner;

/**
 * Person user interface:
 * Connects the MainUI to CustomerUI and EmployeeUI
 * 
 * @author (Gruppe 3)
 */
public class PersonUI
{
    // instance variables
    private CustomerUI customerUI;
    private EmployeeUI employeeUI;

    /**
     * Constructor for objects of class PersonUI
     */
    public PersonUI()
    {
        
    }
    
    /**
     * Opens the person menu
     */ 
    public void open()
    {
        personMenu();
    }
    
    /** 
     * Calls the print person menu method and let the user pick a choice for the menu
     */
    private void personMenu()
    {
        boolean backToMain = false;
        while(!backToMain)
        {
            int choice = makePersonMenu();
            if(choice == 1)
            {
                //Open CustomerUI
                openCustomerUI();
            }
            else
            {
                if(choice == 2)
                {
                    //Open EmployeeUI
                    openEmployeeUI();
                }
                else
                {
                    if(choice == 3)
                    {
                        //Go back
                        backToMain = true;
                    }
                    else
                    {
                        System.out.println("Indtast et nr. mellem 1 og 3");
                        waitInput();
                    }
                }
            }
    }
   }
   
   /**
     * Prints person menu
     */
   private int makePersonMenu()
   {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f ### Person Menu ### ");
        System.out.println(" (1) Kunde menu");
        System.out.println(" (2) Medarbejder menu");
        System.out.println(" (3) Tilbage");
        System.out.println("\n Vælg et nummer");
        
        int choice = keyboard.nextInt();
        return choice;
   }
    
   /**
     * System waits for an input, so the user can read the screen information
     */
    private void waitInput()
    {
        System.out.println("Tryk på en tatst for at forsætte");
        new Scanner(System.in).nextLine();
    }
    
    /**
     * opens the customer menu
     */
    private void openCustomerUI()
    {
        customerUI = new CustomerUI();
        customerUI.open();
    }
    
    /**
     * opens the employee menu
     */
    private void openEmployeeUI()
    {
        employeeUI = new EmployeeUI();
        employeeUI.open();
    }
}
